package com.beiing.tianshuai.tianshuai.model;

import com.beiing.tianshuai.tianshuai.entity.MyFriendListBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;
import com.beiing.tianshuai.tianshuai.util.LogUtils;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Jinni on 2017/8/6 0006.
 */

public class MyFriendListModel implements MyFriendListModelImpl {

    private static final String TAG = "MyFriendListModel";
    private OnRequestListener mListener;

    public MyFriendListModel(OnRequestListener listener) {
        mListener = listener;
    }

    @Override
    public void getMyFriendList(String uid) {
        Observable<MyFriendListBean> loginResult = DataManager.getMyFriendList(
                uid
        );
        Observable<MyFriendListBean> signUpBeanObservable = loginResult.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
        signUpBeanObservable.subscribe(new DisposableObserver<MyFriendListBean>() {

            @Override
            public void onNext(@NonNull MyFriendListBean bean) {
                if (mListener != null) {
                    mListener.onSuccess(bean);
                }
            }

            @Override
            public void onError(@NonNull Throwable e) {
                if (mListener != null) {
                    mListener.onError(e);
                }
            }

            @Override
            public void onComplete() {
                LogUtils.i("------------------ onCompleted ------------------", TAG);
            }
        });
    }

    public interface OnRequestListener {
        void onSuccess(MyFriendListBean bean);

        void onError(Throwable e);
    }
}
